<?php
//include_once("../global.php"); // globale Funktionen
/**
 * Returns href part of html link.
 *
 * @param String $href
 * @param int $idcat
 * @param int $cat
 * @param int $catS
 * @param String $param
 * @return String
 */
function pv_href($href, $idcat=0, $cat=0, $catS=0, $param=""){
	if (preg_match('/\?/', $href)) $char="&";	else $char="?";#check for char
	if ($idcat>0) $href=$href.$char."idcat=$idcat";#check for idcat
	if (preg_match('/\?/', $href)) $char="&";	else $char="?";#again check for char
	if ($cat>0) $href=$href.$char."cat=$cat";#check for cat
	if (preg_match('/\?/', $href)) $char="&";	else $char="?";#and again check for char
	if ($catS>0) $href=$href.$char."catS=$catS";#check for catS
	if (preg_match('/\?/', $href)) $char="&";	else $char="?";#and once again check for char
	if ($param!="") $href=$href.$char.$param;#check for free parameters	
	if (preg_match('/\?/', $href)) $char="&";	else $char="?";#and finally once again check for char
	$_sid=SID;
	if (isset($_sid) && $_sid!=""){#check for cookies
		$href=$href.$char.SID;
	}
	return $href;
}

/**
 * Returns html link.
 *
 * @param String $href
 * @param String $text
 * @param String $class
 * @param int $idcat
 * @param int $cat
 * @param int $catS
 * @param String $onclick
 * @param String $param
 * @return String
 */
function pv_href_link($href, $text, $class="", $idcat=0, $cat=0, $catS=0, $onclick="", $param=""){
	if (preg_match('/\?/', $href)) $char="&";	else $char="?";#check for char
	if ($idcat>0) $href=$href.$char."idcat=$idcat";#check for idcat
	if (preg_match('/\?/', $href)) $char="&";	else $char="?";#again check for char
	if ($cat>0) $href=$href.$char."cat=$cat";#check for cat
	if (preg_match('/\?/', $href)) $char="&";	else $char="?";#and again check for char
	if ($catS>0) $href=$href.$char."catS=$catS";#check for catS
	if (preg_match('/\?/', $href)) $char="&";	else $char="?";#and once again check for char
	if ($param!="") $href=$href.$char.$param;#check for free parameters	
	if (preg_match('/\?/', $href)) $char="&";	else $char="?";#and finally once again check for char
	$_sid=SID;
	if (isset($_sid) && $_sid!=""){#check for cookies
		$href=$href.$char.SID;
	}
	if ($class!="") $link_class=" class=\"$class\""; else $link_class="";
	if ($onclick!="") $link_onclick=" onclick=\"$onclick\""; else $link_onclick="";
	$link="<a href=\"$href\"$link_class $link_onclick>$text</a>";
	return $link;
}

/**
 * Returns html textfield.
 */
function pv_textinput($name, $class="", $stdValue="", $size="", $maxLength="", $hidden=false, $readonly=""){
	($hidden)?$type="hidden":$type="text";
	$result="<input type=\"$type\" name=\"$name\"";
	if ($class!="") $result.=" class=\"$class\"";
	if ($stdValue!="") $result.=" value=\"$stdValue\"";
	if ($size!="") $result.=" size=\"$size\"";
	if ($maxLength!="") $result.=" maxLength=\"$maxLength\"";
    if ($readonly)  $result.=" readonly=\"1\" ";
	$result.=">";
	return $result;
}

/**
 * Returns html textarea.
 */
function pv_textarea($name, $class="", $stdValue="", $cols="", $rows="", $readonly=""){
	$result="<textarea name=\"$name\"";
	if ($class!="") $result.=" class=\"$class\"";
	if ($cols!="") $result.=" cols=\"$cols\"";
	if ($rows!="") $result.=" rows=\"$rows\"";
  if ($readonly) $result.=" readonly=\"1\" ";
	$result.=">";
	if ($stdValue!="") $result.=$stdValue;	
	$result.="</textarea>";
	return $result;
}

/**
* Returns html checkbox
*/
$lbl_id=0;
function pv_checkbox($name, $value, $text, $checked=false, $disabled=false)
{
	global $lbl_id;
	$result="<input type=\"checkbox\" name=\"".$name."\" value=\"".$value."\" id=\"".$text.$lbl_id."\"";
	if ($checked) 
		$result.=" checked";
	if ($disabled) 
		$result.=" disabled";
	$result.="> <label for=\"".$text.$lbl_id."\">".$text."</label>\n";
	$lbl_id++;
	return $result;
}

/**
* Returns html radio button
*/

function pv_radio($name, $value, $text, $checked=false, $disabled=false)
{
	global $lbl_id;
	$result="<input type=\"radio\" name=\"".$name."\" value=\"".$value."\" id=\"".$text.$lbl_id."\"";
	if ($checked) $result.=" checked";
	if ($disabled) $result.=" disabled";
	$result.="> <label for=\"".$text.$lbl_id."\">".$text."</label>\n";
	$lbl_id++;
	return $result;
}

/**
 * Converts string to into mssql format.
 *
 * @param String $datetime_string DD.MM.YY hh:mm:ss
 * @return String MM/DD/YY hh:mm:ss
 */
function convert_string_to_mssql_date($datetime_string){
	$tag=substr($datetime_string, 0, 2);
	$monat=substr($datetime_string, 3, 2);
	$jahr=substr($datetime_string, 6, 4);
	//$jahr="20".$jahr;
//	$zeit=substr($datetime_string, 9, 8);
	$zeit="00:00:00";
//	echo "$monat/$tag/$jahr $zeit";
	return "$monat/$tag/$jahr $zeit";  
}

/**
 * Prints formatted percentage value.
 *
 * @param double $number 0.5
 * @return String 50%
 */
function print_percentage($number)
{
	global $text;
	$formatted = sprintf("%01.2f", $number*100);
	$formatted = str_replace(".", $text["decimalseperator"], $formatted);
	return $formatted."%";
}

/**
 * Prints formatted percentage value.
 *
 * @param double $number
 * @return unknown
 */
function print_percentage_clean($number)
{
	global $text;
	$formatted = sprintf("%01.2f", $number*100);
	$formatted = str_replace(".", $text["decimalseperator"], $formatted);
	if (strlen($formatted)==6) return substr($formatted, 0, 3);
	if (strlen($formatted)==5) return substr($formatted, 0, 2);
	if (strlen($formatted)==4) return substr($formatted, 0, 1);
	return "ERROR";
}

function myround($val, $precision)
{
	global $text;
	$val = round($val, $precision);
	
	// Neue Variante
	$val = sprintf("%01.".$precision."f", $val);
	
	$val = str_replace(".", $text["decimalseperator"], $val);
	return $val;
}



function sortnav($toSort,$orderby,$orderit)
{
$S1 = "_hover";
$S2 = "_hover";
$imagesDir = "images/";
if($orderby == $toSort)
  {
  if($orderit == 'DESC')
    {
     $S1 = "";
    }
  else
    {

    $S2 = "";
    }

  }

return '

<div><img src="'.$imagesDir.'DartRH'.$S1.'.gif"  alt="u" onclick=JSset(\''.$toSort.'_DESC\')>
<img src="'.$imagesDir.'DartHR'.$S2.'.gif" alt="d" onclick=JSset(\''.$toSort.'_ASC\')></div>

 ' ;

return '<tabel>

<tr><td><img src="'.$imagesDir.'updown/oben'.$S1.'.png"  alt="u" onclick=JSset(\''.$toSort.'_DESC\')></td></tr>
<tr><td><img src="'.$imagesDir.'updown/unten'.$S2.'.png" alt="d" onclick=JSset(\''.$toSort.'_ASC\')></td></tr>
</tabel>
 ' ;
}


?>
